<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib prefix="s" uri="/struts-tags"%> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">    
    <title>设备操作</title>  
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--框架必需start-->
	<script type="text/javascript" src="ui/js/jquery.js"></script>
	<script type="text/javascript" src="ui/js/framework.js"></script>
	<link href="ui/css/import_basic.css" rel="stylesheet" type="text/css"/>
	<link rel="stylesheet" type="text/css" id="skin" prePath="/"/>
	<link rel="stylesheet" type="text/css" id="customSkin"/>
	<link href="ui/skins/blue/style.css" rel="stylesheet" type="text/css" id="theme" themeColor="blue"/>
	<!--框架必需end-->
	<script type="text/javascript">
		  /*任务派遣ajax实现 */
		 $(function() {
		   $("#dispatch").click(function() {
		    //提交的参数，taskKind和deviceId是和struts action中对应的接收变量
		       var params = {
		          taskKind : $("#sel-15").val(),
		       	  deviceId : $("#dId").text()
		       };
		       $.ajax({
		   		type: "POST",
		   		url: "dispatch.action",    //提交的地址
		    	data: params,		         //提交的参数
		    	dataType:"text",            //ajax返回值设置为text（json格式也可用它返回，可打印出结果，也可设置成json）
		    	success: function(json){  
		    	var obj = $.parseJSON(json);  //使用这个方法解析json
		                var state_value = obj.dispatchResult;  //dispatchResult是和action中定义的dispatchResult变量的get方法对应的
		    	if(state_value==true){	//任务派遣成功
		    		alert("任务派遣完成！");
		    		location.href='deviceOperation.action?deviceId='+params.deviceId;
		    	}else{							//任务派遣失败
		    		alert("任务派遣失败！");
		    		return false;
		    	}	   		   		 
		    	},
		    	error: function(json){
		   		 var obj = $.parseJSON(json);  
		  	 	 var state_value = obj.dispatchResult; 
		   		 if(state_value==false){
		    		alert("任务派遣失败！");
		  		 }
		     	return false;
		   		 }
		    	});
		     });
		   });
	</script>
	<script type="text/javascript">
		var taskId;
		var dId;
		$(function(){
			$(".img_view").click(function(){
				view($(this));
			});
			$(".img_delete").click(function(){
				onDelete($(this));
			});
		});
		/*任务删除*/
		function onDelete($obj){		
			top.Dialog.confirm("确定要删除吗？",function(){
				var taskId=$obj.parents("tr").find("td").eq(0).html();
				dId = $("#dId").text();
				location.href='taskDel.action?deviceId='+dId+'&taskId='+taskId;	
		});
		}
		/*查看实时图表*/	
		function view($obj){		
			var taskId=$obj.parents("tr").find("td").eq(0).html().trim();
		   	var taskKind=$obj.parents("tr").find("td").eq(1).html(); 
			//$("#lineChart").src='jfreechart.action?taskId='+taskId+'&taskKind='+taskKind;
			//$("#lineChart").location.reload();
			location.href='chart.action?taskId='+taskId+'&taskKind='+taskKind;
		}			
	</script>
  </head>
  
  <body>	
	  	<div style="float:left;width: 100%">  	
	  		<div style="width: 100%;height: 200px;float: left;">
	  			<div class="box1" panelWidth="450" style="float:left;">
					<form >
						<table class="tableStyle" formMode="view" style="font-size: 14;">
							<tr><th colspan="4">设备详细信息</th></tr>
							<tr>
									<td >设备编号:</td><td id="dId"><s:property value="device.dId" /></td>
									<td>设备名称:</td><td><s:property value="device.dName"/></td>
							</tr>
							<tr>
									<td>IP地址:</td><td><s:property value="device.dIp"/></td>
									<td>设备类型:</td>
									<td>
										<s:if test="device.dType==1">
											个人电脑
										</s:if>
										<s:else>
											打印机
										</s:else>
									</td>
							</tr>
							<tr>
									<td>所属管理域:</td><td><s:property value="device.Domain.dmName"/></td>
									<td>系统平台:</td><td><s:property value="device.software"/></td>
							</tr>
							<tr>
									<td>设备硬件参数:</td><td colspan="3"><s:property value="device.hardware"/></td>
							</tr>
						</table>
					</form>
				</div>
	  			<div class="box1" panelWidth="450" style="float:left;">
		  			<form>
						<table class="tableStyle" formMode="view" style="font-size: 14;">
							<tr><th colspan="3">任务派遣</th></tr>
								<tr>
									<td>监控类型:</td>
									<td>
										<select id="sel-15" keepDefaultStyle="true">
											<s:iterator value="kindList" var="kl">
												 <option value="<s:property value="#kl.tkId"/>">
												 	<s:property value="#kl.tkName"/>
												 </option>
											</s:iterator>
										</select>
									</td>
									<td>
										<input type="button" value="派遣" id="dispatch">
									</td>
								</tr>			
								<tr>
									<td>通用型任务:</td>
									<td><input id="oid" placeholder="输入OID"> </td>
									<td><input type="button" value="提交" id="custom"></td>
								</tr>						
							</table>
					</form>
			</div>
	  		</div>
	  		<div style="width: 100%;float: left;">
	  			<div  class="box1" panelWidth="450"  style="float: left;">		
					<div class="box1" panelWidth="450">
						<form>
								<table class="tableStyle" formMode="view" style="font-size: 14;text-align: center;">
								<tr><th colspan="5">任务列表</th></tr>
									<tr>
										<th width="12%">编号</th>
										<th>监控类型</th>
										<th width="18%">任务类型</th>
										<th width="18%">任务状态</th>
										<th width="12%">操作</th>
									</tr>
									<s:iterator value="taskList" var="tl">
										<tr>
											<td>
												<s:property value="#tl.tId"/>
											</td>
											<td>
												<s:property value="#tl.taskKind.tkName"/>
											</td>
											<td>
												<s:if test="#tl.taskKind.tType==1">
													永久性
												</s:if>
												<s:else>
													一次性
												</s:else>
											<td>
												<s:if test="#tl.tState==0">
													未执行
												</s:if>
												<s:else>
													已执行
												</s:else>
											</td>
											<td>
												<span class="img_view hand" title="查看"></span>
												<span class="img_delete hand" title="删除"></span>
											</td>
										</tr>
									</s:iterator>
								</table>
						</form>
					</div>
				</div>	
				<div class="box1" panelWidth="450" style="float: left;">
						<form>
								<table class="tableStyle" formMode="view" style="font-size: 14;text-align: center;">
									<tr><th colspan="3">通用型任务列表</th></tr>
									<tr>
										<th width="12%">编号</th>
										<th>OID</th>
										<th width="12%">操作</th>
									</tr>
									<s:iterator value="taskList" var="tl">
										<tr>
											<td>
												<s:property value="#tl.tId"/>
											</td>
											<td>
												<!--<s:property value="#tl.taskKind.tkName"/>-->
											</td>
											<td>
												<span class="img_view hand" title="查看"></span>
												<span class="img_delete hand" title="删除"></span>
											</td>
										</tr>
									</s:iterator>
									
								</table>
						</form>
					</div>
			</div>	
	  	</div>				
  </body>
</html>
